import { reqGetSearchGoodsData } from "@/api"

export default {
  namespaced: true,
  state: {
    searchGoodsData: {}
  },
  mutations: {
    // 设置searchGoodsData数据值
    setSearchGoodsData(state, value) {
      state.searchGoodsData = value
    }
  },
  // 异步请求数据并设置数据
  actions: {
    async getSearchGoodsData({ commit }, searchParams) {
      const res = await reqGetSearchGoodsData(searchParams);
      if (res.code === 200) {
        commit('setSearchGoodsData', res.data)
      } else {
        console.log(res.message);
      }
    }
  },
  getters: {
    // 将attrsList、goodsList、trademarkList从state中的searchGoodsData数据解构出来
    attrsList(state) {
      return state.searchGoodsData.attrsList
    },
    goodsList(state) {
      return state.searchGoodsData.goodsList
    },
    trademarkList(state) {
      return state.searchGoodsData.trademarkList
    },
    // total总数据
    total(state) {
      return state.searchGoodsData.total;
    },
    // 当前页
    pageNo(state) {
      return state.searchGoodsData.pageNo;
    },
    // 每页数量
    // pageSize(state) {
    //   return state.searchGoodsData.pageSize;
    // },
    // 总页数
    // totalPage(state) {
    //   return state.searchGoodsData.totalPage;
    // }

  }
}